package cn.lg.org.service.impl;

import cn.lg.basic.util.PageList;
import cn.lg.org.domain.Employee;
import cn.lg.org.mapper.EmployeeMapper;
import cn.lg.org.query.EmployeeQuery;
import cn.lg.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 员工业务实现类
 */
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)// 配置查询事务
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> queryAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public Employee queryById(Long id) {
        return employeeMapper.loadById(id);
    }

    @Override
    @Transactional
    public void save(Employee employee) {
        employeeMapper.save(employee);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        employeeMapper.remove(id);
    }

    @Override
    public PageList queryData(EmployeeQuery employeeQuery) {
        Integer count = employeeMapper.queryCount(employeeQuery);
        if(count == 0) {
            return new PageList();
        }
        List<Employee> employees = employeeMapper.queryData(employeeQuery);
        return new PageList(count,employees);

    }

    @Override
    @Transactional
    public void patchRemove(List<Long> ids) {
        employeeMapper.patchRemove(ids);
    }
}
